<?php
/**
 * 通过关键字获取餐厅列表
 * 
 * @author zhangchao
 * @since 2012-05-18
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	cgi::both($g_cgival["rstrt_str"], "rstrt_str", "");
	$g_cgival["rstrt_str"] = string::un_script_code($g_cgival["rstrt_str"]);
	$g_cgival["rstrt_str"] = string::un_html($g_cgival["rstrt_str"]);
}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	$g_show['data'] = array();
	if($g_cgival["rstrt_str"] != '')
	{
		$site_id = admin::admin_get_user_site_id();
		
		$db_web_rstrt = new db_web_rstrt();
		$rstrt_list = $db_web_rstrt->admin_get_rstrt_list_by($site_id, $g_cgival["rstrt_str"], 0, 0, 0, 1);
		foreach ($rstrt_list as $value) {
			$rstrt_info = array();
			$rstrt_info['id'] = $value['RstrtID'];
			$rstrt_info['name'] = $value['RstrtName'];
			$g_show['data'][] = $rstrt_info;
		}
	}
}

try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_cover_template_add_post.php");
	
	check_cgi_pro();
	get_data();
	$g_show["error"] = 0;
	$g_show["errmsg"] = '';
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	echo output::json('json',$g_show);
}

?>